<?php
declare (strict_types=1);

namespace app\admin\controller;

use think\App;
use app\common\builder\TableBuilder;
use app\common\builder\TableFront;
use think\response\Json;

class BusinessVideoApply extends Base
{

    //主键
    protected $pk = 'id';

    //主模型
    protected $model = '\app\common\model\BusinessVideoApply';

    protected $hasOne = ['business'];

    public function index()
    {
        return $this->setTable();
    }

    //自动构建table,按需修改
    public function setTable()
    {
        $tableFront = TableFront::getInstance()
            ->addRow(['type' => 'checkbox', 'fixed' => 'left', 'title' => '全选'])
            ->addRow(['field' => 'id', 'sort' => true, 'title' => 'ID', 'width' => 80])
            ->addRow(['field' => 'title', 'title' => '商家名称', 'templet' => '<div>{{d.business.title}}</div>'])
            ->addRow(['field' => 'contacts', 'title' => '联系人', 'templet' => '<div>{{d.business.contacts}}</div>'])
            ->addRow(['field' => 'mobile', 'title' => '手机号', 'width' => 110, 'templet' => '<div>{{d.business.mobile}}</div>'])
            ->addRow(['field' => 'customer_tel', 'title' => '客服电话', 'width' => 110, 'templet' => '<div>{{d.business.customer_tel}}</div>'])
            ->addRow(['field' => 'create_time', 'title' => '申请时间', 'width' => 150])
            ->addRow(['field' => 'status', 'title' => '状态'])
            ->addRow(['fixed' => 'right', 'align' => 'center', 'toolbar' => '#rightBtn', 'title' => '操作', 'width' => 80]);

        return TableBuilder::getInstance()
            ->addColumns($tableFront)
            ->addRightButtons(['edit' => ['title' => '审核', 'width' => 1920, 'height' => 1080]])
            ->addTopButtons(['deleteAll'])
            ->setSearch($this->setSearch())
            ->addExtraHtml(['BusinessApply'])
            ->addSwitchTool([['name' => 'status', 'pk' => 'id', 'text' => '开启|关闭']])
            ->fetch();
    }

    //自动构建Search，按需修改
    public function setSearch()
    {
        return TableFront::getInstance()
            ->setSearch(['uid', '会员编号/用户名/手机号', 'input', '', '\app\common\model\User', 'code|account|mobile,id'])
            ->setSearch(['contacts__mobile__customer_tel', '联系人/手机号/客服电话', 'input', '', '', '', 'like'])
            ->setSearch(['title', '店铺名称', 'input', '', '', '', 'like'])
            ->setSearch(['status', '状态', 'select', [1 => '待审核', 2 => '已审核', 3 => '已驳回']]);

    }

    public function edit($name = '', $id = '', $tpl = 'business_video_apply/edit', $info = '')
    {
        return parent::edit($name, $id, $tpl, $info); // TODO: Change the autogenerated stub
    }

    public function save($param = [], $model = true): Json
    {
        return parent::save($param, $model); // TODO: Change the autogenerated stub
    }
}
